package org.kisekiproject.persistance {
	import flash.net.SharedObject;
	
	import org.kisekiproject.log.Log;

	/**
	 * Store data in a local shared object.
	 */
	public class SharedObjectPersister implements IPersister {

		private var _key:String;
		private var _so:SharedObject;

		/**
		 * Constructor.
		 */
		public function SharedObjectPersister(key:String="progress") {
			_key=key;
			_so=SharedObject.getLocal(_key);
		}

		/**
		 * Load data.
		 */
		public function load():Object {
			Log.debug("Loading shared object data...");

			var data:Object=_so.data.data;

			for (var s:String in data)
				trace(s+": "+data[s]);
			
			return data;
		}

		/**
		 * Save data.
		 */
		public function save(data:Object):void {
			Log.debug("Saving shared object data...");

			_so.data.data=data;
			_so.flush();
		}
	}
}